/*
 * CRenderer.h
 *
 *  Created on: 04.09.2011
 *      Author: kirill
 *      Copyright: LGPL
 */

#ifndef CRENDERER_H_
#define CRENDERER_H_

#include "../BasicTypes.h"
#include "ShaderTypes.h"
#include "CFrameBuffer.h"

/*
 *
 */
class CRenderer
{
private:
	CFrameBuffer*         frameBuffer;
	CColorRenderBuffer*   renderBuffer;
	CTextureRenderBuffer* textureBuffer;
	SCREEN_DIMENSION      dimension;
	CShaderProgramm**     programmArray;

	bool                  initialized;
protected:
	void RenderObject( GAME_OBJECT* Object, const glm::mat4 ProjectionMatrix, const glm::mat4 ViewMatrix,
                       const glm::vec3 LightDirection, const glm::vec3 AmblientColor );
	void RenderGuiObject( const GLuint Texture, const glm::vec2 &Position, const glm::vec2 &Size, const RENDER_MODEL_INFO* Dummy,
						  CShaderProgramm *CurrentShader );
	void InitializeFrameBuffer( const UINT WindowWidth, const UINT WindowHeight );
	glm::mat4 CalculateGuiMatrix( const glm::vec2 &Position, const glm::vec2 &Sizes ) const;
public:
	CRenderer();
	virtual ~CRenderer();
	bool Init( const SCREEN_DIMENSION &Dimension, CShaderProgramm **ProgrammArray );
	void SetRenderParams( const VISUAL_PARAMS &Parametrs );

	/*
	 * Only one camera supported now
	 */
	bool StartNewFrame( const GLuint VertexArrayName );
	void RenderCameraFrame( const std::vector<GAME_OBJECT*>  &SortedVisibleObjects, const GAME_CAMERA &CurrentCamera );
	void RenderFinalFrame( const std::vector<GUI_ELEMENT*> &GuiElementsArray, const RENDER_MODEL_INFO* Dummy );
};

#endif /* CRENDERER_H_ */
